package com.masterclient.app.businessmodule.homemodule.view.footer;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.view.View;

import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;

public class HomeClassicFooter extends ClassicsFooter {
    public HomeClassicFooter(Context context) {
        super(context);
        setBackgroundColor(Color.parseColor("#ffffff"));
    }

    public HomeClassicFooter(Context context, AttributeSet attrs) {
        super(context, attrs);
        setBackgroundColor(Color.parseColor("#ffffff"));
    }

    @Override
    public int onFinish(@NonNull RefreshLayout layout, boolean success) {
        if (!mNoMoreData) {
            mTitleText.setText(success ? mTextFinish : mTextFailed);
            mTitleText.setTextSize(9);
            mTitleText.setTextColor(Color.parseColor("#ffcccccc"));
            final View progressView = mProgressView;
            Drawable drawable = mProgressView.getDrawable();
            if (drawable instanceof Animatable) {
                if (((Animatable) drawable).isRunning()) {
                    ((Animatable) drawable).stop();
                }
            } else {
                progressView.animate().rotation(0).setDuration(0);
            }
            progressView.setVisibility(GONE);
            return 0;//延迟500毫秒之后再弹回
        }else {
            mTitleText.setText("别拉了，已经到底了~");
            mTitleText.setTextSize(9);
            mTitleText.setTextColor(Color.parseColor("#ffcccccc"));
            return 0;
        }
    }


    @Override
    public void onStartAnimator(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) {
        super.onStartAnimator(refreshLayout, height, maxDragHeight);
    }
}
